<?php
class Pager{
    
    private $total_rows  = 0;
    private $currentpage = 1;
    private $rowperpage  = 5;    
    private $link        = "";
    
    private $numlink     = 6;
    
    public function __construct($configs = array()){
        foreach($configs as $key=>$value){
            if(property_exists($this, $key)){
                $this->{$key} = $value;
            }
        }        
    }
    
    public function getRowStart(){
        $temp = ($this->currentpage-1)*$this->rowperpage;
        return $temp;
    }
    
    public function getTotalRows(){
        return $this->total_rows;
    }
    
    public function getCurrentPage(){
        return $this->currentpage;
    }
    
    public function getRowPerPage(){
        return $this->rowperpage;
    }
    
    public function showPager(){
        $lastpage = ceil($this->total_rows/$this->rowperpage);
        $prev = ($this->currentpage > 1)? $this->currentpage-1:1;
        $next = ($this->currentpage < $lastpage)? $this->currentpage+1:$lastpage;
        
        if($this->currentpage != 1){            
            echo    "<a href='{$this->link}&page=1'>&laquo; First</a>"; 
            echo    "<a href='{$this->link}&page={$prev}'>&laquo; Previous</a>";
        }
        
                
        $i = $this->currentpage - 2;
        $j = $this->currentpage + 2;
        if($i <= 0)
            $i = 1;
        if($j > $lastpage)
            $j = $lastpage;
        for(; $i <= $j; $i++){
            if($this->currentpage != $i){
                echo "<a href='{$this->link}&page={$i}'>{$i}</a>";
            }else{
                echo "<a href='{$this->link}&page={$i}' class='select'>{$i}</a>";
            }
        }
        
        
        if($this->currentpage != $lastpage){ 
            echo    "<a href='{$this->link}&page={$next}'>Next &raquo;</a>";        
            echo    "<a href='{$this->link}&page={$lastpage}'>Last &raquo;</a>";
        }
    }
    
    
}
?>